<button class="btn btn-info" type="button" onclick="backtoMain()">返回</button><br>
<table class="table" id="somainDiv">
    <thead>
    <tr>
        <th>序号</th>
        <th>销售单编号</th>
        <th>创建时间</th>
        <th>客户名称</th>
        <th>经手人</th>
        <th>销售单总价</th>
        <th>未付款金额</th>
        <th>付款方式</th>
        <th>最低预付款金额</th>
        <th>销售单状态</th>
    </tr>
    </thead>
    <tbody id="tableBody"></tbody>
</table>


<script id="soItemReportTemplate" type="text/html">
    {{each data value index}}
    <tr>
        <td>{{index+1}}</td>
        <td>{{value.soId}}</td>
        <td>{{value.createTime}}</td>
        <td>{{value.customerList[0].name}}</td>
        <td>{{value.scmUserList[0].name}}</td>
        <td>{{value.soTotal}}</td>
        <td>{{value.notPayPrice}}</td>
        <td>{{value.payType}}</td>
        <td>{{value.prePayFee}}</td>
        <td>{{value.status}}</td>
    </tr>
    {{/each}}
</script>

<script>
    $(function () {
        Ajax.post(
            "/selectSoMainReportList",
            {date:sessionStorage.getItem("somaindate")},
            function (result) {
                var notPayPrice=0
                for(var i=0;i<result.data.length;i++){
                    if(result.data[i].status==1){
                        notPayPrice=result.data[i].poTotal
                        result.data[i]["notPayPrice"]=notPayPrice
                    }
                    if(result.data[i].status==2){
                        notPayPrice=result.data[i].poTotal-result.data[i].prePayFee
                        result.data[i]["notPayPrice"]=notPayPrice
                    }
                    if(result.data[i].status==3){
                        notPayPrice=0
                        result.data[i]["notPayPrice"]=notPayPrice
                    }
                    if(result.data[i].status==4){
                        notPayPrice=0
                        result.data[i]["notPayPrice"]=notPayPrice
                    }
                    if(result.data[i].status==5){
                        notPayPrice=result.data[i].poTotal-result.data[i].prePayFee
                        result.data[i]["notPayPrice"]=notPayPrice
                    }
                }
                for(var i=0;i<result.data.length;i++){
                    if(result.data[i].status==1){
                        result.data[i].status="新增";
                    }
                    if(result.data[i].status==2){
                        result.data[i].status="已收货";
                    }
                    if(result.data[i].status==3){
                        result.data[i].status="已收款";
                    }
                    if(result.data[i].status==4){
                        result.data[i].status="已了结";
                    }
                    if(result.data[i].status==5){
                        result.data[i].status="已预付";
                    }
                }
                var div=document.getElementById("tableBody")
                var html=template('soItemReportTemplate',{data:result.data})
                div.innerHTML=html
            }
        )
    })
    function backtoMain() {
        sessionStorage.setItem("backsomaindate",sessionStorage.getItem("somaindate"))
        show("/report/somainReport.html")
    }
</script>
